/*
 * TOP SECRET Copyright 2006-2015 Transsion.com All right reserved. This software is the confidential and proprietary
 * information of Transsion.com ("Confidential Information"). You shall not disclose such Confidential Information and
 * shall use it only in accordance with the terms of the license agreement you entered into with Transsion.com.
 */
package com.yunji.framework_template.biz.crawler.cd;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.yunji.framework_template.biz.crawler.ContentImageHandler;
import com.yunji.framework_template.biz.crawler.NewsCrawler;
import com.yunji.framework_template.biz.crawler.SourceType;
import com.yunji.framework_template.common.enumeration.CountryCode;
import com.yunji.framework_template.common.enumeration.NewsType;

/**
 * ClassName:NationNewsCrawler <br/>
 * Date: 2018年12月18日 下午3:31:24 <br/>
 * 
 * @author fenglibin1982@163.com
 * @Blog http://blog.csdn.net/fenglibing
 * @version
 * @see
 */
@Service
public class LepotentielNewsCrawler extends NewsCrawler {

    @Resource
    private LepotentielNewsImageHandler lepotentielNewsImageHandler;

    @Override
    public boolean isOkUrl(String url) {
        // 通过判断url的path中是否包括年月来判断其是否为新闻详情页
        URI uri;
        try {
            if (url == null || url.trim().length() == 0) {
                return false;
            }
            if (url.startsWith("mailto") || url.toLowerCase().startsWith("javascript")) {
                return false;
            }
            uri = new URI(url);
            String host = uri.getHost();
            if(host==null) {
                return false;
            }
            if (host.indexOf("lepotentielonline.com") < 0) {
                return false;
            }
            String path = uri.getPath();
            String[] pathArr = path.split("/");
            if (pathArr.length == 5) {
                return true;
            }
        } catch (URISyntaxException e) {
        }
        return false;
    }

    @Override
    public ContentImageHandler getContentImageHandler() {
        return lepotentielNewsImageHandler;
    }

    @Override
    public List<SourceType> getSourceTypeList() {
        List<SourceType> sourceTypeList = new ArrayList<SourceType>();
        sourceTypeList.add(SourceType.builder().url("http://lepotentielonline.net").newsType(NewsType.HOT).build());
        sourceTypeList.add(SourceType.builder().url("http://lepotentielonline.net/category/a-la-une/").newsType(NewsType.HOT).build());
        sourceTypeList.add(SourceType.builder().url("http://lepotentielonline.net/category/rd-congo/").newsType(NewsType.EDUCATION).build());
        sourceTypeList.add(SourceType.builder().url("http://lepotentielonline.net/category/politique/").newsType(NewsType.VIDEO).build());
        sourceTypeList.add(SourceType.builder().url("http://lepotentielonline.net/category/economie/").newsType(NewsType.IMAGE).build());
        sourceTypeList.add(SourceType.builder().url("http://lepotentielonline.net/category/societe/").newsType(NewsType.SPORT).build());
        sourceTypeList.add(SourceType.builder().url("http://lepotentielonline.net/category/sport/").newsType(NewsType.LIFESTYLE).build());
        sourceTypeList.add(SourceType.builder().url("http://lepotentielonline.net/category/provinces/").newsType(NewsType.FUN).build());
        sourceTypeList.add(SourceType.builder().url("http://lepotentielonline.net/category/internationale/").newsType(NewsType.HOUSE).build());
        sourceTypeList.add(SourceType.builder().url("http://lepotentielonline.net/category/afrique/").newsType(NewsType.ASKANDANSWER).build());
        sourceTypeList.add(SourceType.builder().url("http://lepotentielonline.net/category/monde/").newsType(NewsType.HEALTH).build());
        sourceTypeList.add(SourceType.builder().url("http://lepotentielonline.net/category/dossier-elections/").newsType(NewsType.MILITARY).build());
        sourceTypeList.add(SourceType.builder().url("http://lepotentielonline.net/category/editorial/").newsType(NewsType.CAR).build());
        sourceTypeList.add(SourceType.builder().url("http://lepotentielonline.net/category/forum-2/").newsType(NewsType.TECH).build());
        sourceTypeList.add(SourceType.builder().url("http://lepotentielonline.net/category/revue-de-presse/").newsType(NewsType.FINANCE).build());
        sourceTypeList.add(SourceType.builder().url("http://lepotentielonline.net/2018/03/23/nous-contacter/").newsType(NewsType.NEWS).build());
        sourceTypeList.add(SourceType.builder().url("http://lepotentielonline.net/cart/").newsType(NewsType.BUSINESS).build());
        sourceTypeList.add(SourceType.builder().url("http://lepotentielonline.net/purchases/").newsType(NewsType.ENTERTAINMENT).build());

        return sourceTypeList;
    }

    @Override
    public Set<String> getCountryCodeSet() {
        Set<String> countryCodeSet = new HashSet<String>();
        countryCodeSet.add(CountryCode.CD.name());
        return countryCodeSet;
    }
}
